package com.company.project.robot.controller;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.robot.entity.WechatGroupEntity;
import com.company.project.robot.service.WechatGroupService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;

import com.company.project.common.utils.DataResult;



/**
 * @author ZYF
 * @date 2021/10/29 14:36
 */
@Api(tags = "微信群控制层")
@Controller
@Slf4j
@RequestMapping("/")
public class    WechatGroupController {


    @Autowired
    WechatGroupService wechatGroupService;


    /**
     * 跳转到页面
     */
    @GetMapping("/index/wechatGroup")
    public String wechatGroupList() {
        return "wechatgroup/list";
    }

    /**
     * 跳转到修改页面
     */
    @GetMapping("/index/wechatGroup/info")
    public String wechatGroupInfo(String id, Model model) {
        model.addAttribute("id",id);
        return "wechatgroup/edit";
    }



    @ApiOperation(value = "查询分页数据")
    @PostMapping("wechatGroup/listByPage")
    @ResponseBody
    public DataResult findListByPage(@RequestBody WechatGroupEntity wechatGroup){
        Page page = new Page(wechatGroup.getPage(), wechatGroup.getLimit());
        LambdaQueryWrapper<WechatGroupEntity> queryWrapper = Wrappers.lambdaQuery();
//        //查询条件示例
        if(StrUtil.isNotEmpty(wechatGroup.getGroupName())){
            queryWrapper.like(WechatGroupEntity::getGroupName, wechatGroup.getGroupName());
        }
        if(StrUtil.isNotEmpty(wechatGroup.getRobotId())){
            queryWrapper.eq(WechatGroupEntity::getRobotId,wechatGroup.getRobotId());
        }
        IPage<WechatGroupEntity> iPage = wechatGroupService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

    @GetMapping("/wechatGroup/{id}")
    @ApiOperation(value = "查询详情接口")
    @ResponseBody
    public DataResult detailInfo(@PathVariable("id") String id) {
        return DataResult.success(wechatGroupService.getById(id));
    }

    @ApiOperation(value = "更新")
    @PutMapping("wechatGroup/update")
    @ResponseBody
    public DataResult update(@RequestBody WechatGroupEntity wechatGroup){
        wechatGroupService.updateById(wechatGroup);
        return DataResult.success();
    }







}
